package StudyCode.summary.mycollection;

import java.lang.reflect.Array;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ArrayAndRemovesAnElementAtTheSpecifiedIndex {
	public static <T> T[] removeElementAtIndex(Class<T> typeClass,
	                                           T[] array, int index) {
		@SuppressWarnings("unchecked")
		T[] newArray = (T[]) Array.newInstance(typeClass, array.length - 1);
		int newArrayIndex = 0;
		for (int originalArrayIndex = 0; originalArrayIndex < array.length; originalArrayIndex++) {
			if (originalArrayIndex != index) {
				newArray[newArrayIndex] = array[originalArrayIndex];
				newArrayIndex++;
			}
		}
		return newArray;
	}
}
